<template>
	<view class="box">
		<view class="lis">
			实际价格:
		</view>
		<view class="shurubox" v-if="types==1">
			<input type="digit" :value="moneys"  disabled="" />
			<text>万</text>
		</view>
		<view class="shurubox" v-if="types==2">
			<input type="digit" :value="moneys"  disabled="" />
			<text>元/月</text>
		</view>
		<view class="lis">
			成交价:
		</view>
		<view class="shurubox">
			<input type="digit" :value="money" placeholder="请输入成交金额" @input="priceshuru" />
			<text>元</text>
		</view>
		<view class="lis">
			佣金:
		</view>
		<view class="shurubox">
			<input type="digit" :value="commissions" placeholder="请输入佣金" @input="commission" />
			<text>元</text>
		</view>
		
		<view class="lis">
			备注:
		</view>
		<view class="shuruboxs">
			<textarea :value="remarks" placeholder="请输入备注" @input="beizhu" />
		</view>
		
		<view class="uploadaccessory">
			附件上传
		</view>
		<UpLoadimg @successImg="successImg1" :imgList="imgList" @deleteImg="deleteImg1" :imgMaxNum="9"></UpLoadimg>
		<view class="submit" @click="submit">
			提交
		</view>
		<u-popup v-model="show" mode="center">
			<view class="tangchubox">
				<view class="submits">审核失败原因</view>
				<view class="reason">
					{{cause}}
				</view>
			</view>
		</u-popup>
	</view>
</template>

<script>
	import UpLoadimg from "../../components/UpLoadimg/index.vue"
	import {
		addrecord,
		getfailed,
		particularsRecordList
	} from "../../api/api/index.js"
	export default {
		data() {
			return {
				imgList: [],
				guard_house_id: 0,
				follow_up_id: 0,
				money: 0,
				cause: "",
				money: "",
				show: false,
				type: "",
				jiaoyi_id: 0,
				moneys:20000,
				remarks:"",
				commissions:"",
				types:1
			}
		},
		components: {
			UpLoadimg
		},
		methods: {
			successImg1(data) {
				this.imgList.push(data)
			},
			deleteImg1(index) {
				this.imgList.splice(index, 1)
			},
			priceshuru(e) {
				this.money = e.detail.value
			},
			submit() {
				if (this.type == "fail") {
					let image = []
					for (let i = 0; i < this.imgList.length; i++) {
						image.push(this.imgList[i].url)
					}
					let data = {
						money: this.money,
						guard_house_id: this.guard_house_id,
						follow_up_id: this.follow_up_id,
						imgs: image.join("|"),
						id: this.jiaoyi_id,
						commissions:this.commissions,
						remarks:this.remarks,
						original_price:this.moneys
					}
					
					console.log(data)
					debugger
					getfailed(data).then(res => {
						uni.showToast({
							title: res.message,
							icon: "none",
							duration: 1500
						})
						setTimeout(function() {
							uni.navigateBack({})
						}, 1500)
					})
				} else {
					debugger
					let image = []
					for (let i = 0; i < this.imgList.length; i++) {
						image.push(this.imgList[i].url)
					}
					let data = {
						money: this.money,
						guard_house_id: this.guard_house_id,
						follow_up_id: this.follow_up_id,
						imgs: image.join("|"),
						commissions:this.commissions,
						remarks:this.remarks,
						original_price:this.moneys
					}
					addrecord(data).then(res => {
						uni.showToast({
							title: res.message,
							icon: "none",
							duration: 1500
						})
						setTimeout(function() {
							uni.navigateBack({})
						}, 1500)

					})
				}
			},
			beizhu(e){
				this.remarks=e.detail.value
			},
			commission(e){
				this.commissions=e.detail.value
			}


		},
		onLoad(e) {
			console.log(e.follow_up_id)
			this.guard_house_id = e.guard_house_id
			this.follow_up_id = e.follow_up_id
			this.type = e.type
			this.types = e.types
			this.jiaoyi_id = e.jiaoyi_id
			this.moneys=e.moneys
			if (e.type == "fail") {
				let data = {
					id: e.jiaoyi_id
				}
				particularsRecordList(data).then(res => {
					this.show = true
					this.money = res.data.money
					this.cause = res.data.audit_feedback
					this.remarks=res.data.remarks
					this.commissions=res.data.commissions
					this.moneys=res.data.original_price
					this.imgList = res.data.imgs.map(v => {
						return {
							url: v
						}
					})
				})
			}
		}
	}
</script>

<style scoped lang="less">
	.box {
		position: fixed;
		top: 0;
		bottom: 0;
		left: 0;
		right: 0;
		background-color: #EFEFEF;
		padding: 40rpx;
		box-sizing: border-box;
		.shuruboxs{
			width: 677rpx;
			height: 400rpx;
			background-color: #ffffff;
			border-radius: 10rpx;
			border: solid 2rpx #dfdfdf;
			padding: 20rpx;
			box-sizing: border-box;
		}
		.shurubox {
			width: 677rpx;
			height: 90rpx;
			background-color: #ffffff;
			border-radius: 10rpx;
			border: solid 2rpx #dfdfdf;
			display: flex;
			justify-content: space-between;
			padding: 20rpx;
			box-sizing: border-box;

			input {
				width: 550rpx;
				font-family: MicrosoftYaHei;
				font-size: 24rpx;
			}

			text {
				font-family: MicrosoftYaHei;
				font-size: 30rpx;
				color: #000000;
			}
		}

		.uploadaccessory {
			font-family: MicrosoftYaHei-Bold;
			font-size: 30rpx;
			color: #000000;
			margin-top: 42rpx;
			margin-left: 10rpx;
			margin-bottom: 30rpx;
			font-weight: 700;
		}
		.lis{
			font-family: MicrosoftYaHei-Bold;
			font-size: 30rpx;
			color: #000000;
			margin-top: 5rpx;
			margin-left: 10rpx;
			margin-bottom: 30rpx;
			font-weight: 700;
		}

		.submit {
			width: 100%;
			height: 90rpx;
			background-color: #fc7b63;
			border-radius: 5rpx;
			text-align: center;
			line-height: 90rpx;
			color: #FFFFFF;
			font-family: MicrosoftYaHei;
			font-size: 30rpx;
			margin-top: 50rpx;
			margin-bottom: 100rpx;
		}
	}

	.tangchubox {
		width: 658rpx;

		.reason {
			font-size: 30rpx;
			padding: 20rpx;
			box-sizing: border-box;
			height: 500rpx;
		}

		.submits {
			width: 658rpx;
			height: 100rpx;
			text-align: center;
			line-height: 100rpx;
			background-color: #ef0000;
			color: #FFFFFF;
		}
	}
</style>
